package com.baidu.ai.aip.faceAPI;

import com.baidu.ai.aip.bean.FaceSearchBean;
import com.baidu.ai.aip.bean.FaceVerifyBean;
import com.baidu.ai.aip.bean.JsonBean;
import com.baidu.ai.aip.utils.Base64Util;
import com.baidu.ai.aip.utils.GsonUtils;

import java.io.IOException;

public class FaceServiceImpl implements FaceService {
    @Override
    public JsonBean faceSearch(String imageUrl) throws IOException {
        String imageBase64 = Base64Util.encode(imageUrl);
        String jsonResult = FaceSearch.faceSearch(imageBase64);
        JsonBean jsonBean =  GsonUtils.fromJson(jsonResult, FaceSearchBean.class);
        return jsonBean;
    }

    @Override
    public JsonBean faceVerify(String imageUrl, String groupList, String userId) throws IOException {
        String imageBase64 = Base64Util.encode(imageUrl);
        String jsonResult = FaceVerify.verify(imageBase64, groupList, userId);
        JsonBean jsonBean =  GsonUtils.fromJson(jsonResult, FaceVerifyBean.class);
        return jsonBean;
    }
}
